#!/usr/bin/env python

import unittest
import hippo
import sys

def test_loads_parameters():
    parser = hippo.OptionParser()
    inputArgs = ['a', 'b', 'c']
    (options, args) = parser.parse_args(inputArgs)
    assert args == inputArgs
    assert options == {}

def test_parses_options():
    parser = hippo.OptionParser()
    inputArgs = ['--verbose', '--depth=5', '--name', 'Annabell', 'done']
    parser.add_option('-v', '--verbose', action='store_true')
    parser.add_option('--depth', type=int)
    parser.add_option('--name')
    (options, args) = parser.parse_args(inputArgs)
    assert args == ['done']
    assert options.verbose == True
    assert options.depth == 5
    assert options.name == 'Annabell'

def test_reads_named_config_file_for_defaults():
    parser = hippo.OptionParser(config_file='config1.config')
    inputArgs = ['done']
    parser.add_option('--name')
    (options, args) = parser.parse_args(inputArgs)
    assert options.name == 'Gertrude'

def test_gets_config_files_from_sys_argv():
    sys.argv[0] = 'config2.py'
    print sys.argv
    parser = hippo.OptionParser()
    inputArgs = ['done']
    parser.add_option('--name')
    (options, args) = parser.parse_args(inputArgs)
    assert options.name == 'Hariet'

def test_reads_named_config_section():
    parser = hippo.OptionParser(config_file='config3.config', config_section='OTHER_OPTIONS')
    inputArgs = ['done']
    parser.add_option('--name')
    (options, args) = parser.parse_args(inputArgs)
    assert options.name == 'Peggy'

def test_can_override_config_file_setting():
    parser = hippo.OptionParser(config_file='config4.config')
    inputArgs = ['--name', 'Blanche', 'done']
    parser.add_option('--name')
    (options, args) = parser.parse_args(inputArgs)
    assert options.name == 'Blanche'
